﻿Imports System.Data.SqlClient

Public Class clsSueldosAcumulados
    Private mintcIdSueldo As Integer
    Private mdatcFecha As Date
    Private mintcIdClien01 As Integer
    Private mstrcRazonSo01 As String
    Private mintcNomina As Integer
    Private mintcAnio As Integer
    Private mintcFolio As Integer
    Private mdblcTotal As Double
    Public Property IdSueldo() As Integer
        Get
            Return mintcIdSueldo
        End Get
        Set(ByVal value As Integer)
            mintcIdSueldo = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatcFecha
        End Get
        Set(value As Date)
            mdatcFecha = value
        End Set
    End Property
    Public Property IdClien01() As Integer
        Get
            Return mintcIdClien01
        End Get
        Set(ByVal value As Integer)
            mintcIdClien01 = value
        End Set
    End Property
    Public Property RazonSo01() As String
        Get
            Return mstrcRazonSo01
        End Get
        Set(ByVal value As String)
            mstrcRazonSo01 = value
        End Set
    End Property
    Public Property Nomina() As Integer
        Get
            Return mintcNomina
        End Get
        Set(ByVal value As Integer)
            mintcNomina = value
        End Set
    End Property
    Public Property Anio() As Integer
        Get
            Return mintcAnio
        End Get
        Set(ByVal value As Integer)
            mintcAnio = value
        End Set
    End Property
    Public Property Folio() As Integer
        Get
            Return mintcFolio
        End Get
        Set(ByVal value As Integer)
            mintcFolio = value
        End Set
    End Property
    Public Property Total() As Double
        Get
            Return mdblcTotal
        End Get
        Set(value As Double)
            mdblcTotal = value
        End Set
    End Property
    Public Sub Insertar()

        Dim sql As String = "Insert Into SueldosAcumulados (" & _
                             "IdSueldo," & _
                             "Fecha," & _
                             "cIdClien01," & _
                             "cRazonSo01," & _
                             "Nomina," & _
                             "Anio," & _
                             "Folio," & _
                             "Total)" & _
                             "VALUES (" & _
                             "@IdSueldo," & _
                             "@Fecha," & _
                             "@cIdClien01," & _
                             "@cRazonSo01," & _
                             "@Nomina," & _
                             "@Anio," & _
                             "@Folio," & _
                             "@Total)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdSueldo", mintcIdSueldo)
        Command.Parameters.AddWithValue("Fecha", mdatcFecha)
        Command.Parameters.AddWithValue("cIdClien01", mintcIdClien01)
        Command.Parameters.AddWithValue("cRazonSo01", mstrcRazonSo01)
        Command.Parameters.AddWithValue("Nomina", mintcNomina)
        Command.Parameters.AddWithValue("Anio", mintcAnio)
        Command.Parameters.AddWithValue("Folio", mintcFolio)
        Command.Parameters.AddWithValue("Total", mdblcTotal)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el permiso", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

    Function consecutivo() As Double
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT Max(IdSueldo) As id From SueldosAcumulados "
        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read() Then
            consecutivo = rdBuscar("ID") + 1
        Else
            consecutivo = 1
        End If

        rdBuscar.Close()
        cnConn.Close()
    End Function
End Class
